/*
 * MyGWT User Extensions
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.mygwt.ux.client.widgets.wizard;


import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

/**
 * 
 * @author Chris Worley
 *
 */
public abstract class WizardPage extends Composite {

  /** wizard reference */
  private Wizard wizard;

  /** page icon */
  private String icon;

  /** page title */
  private String pageTitle;

  /** page message */
  private String message;

  /**
   * Default constructor
   */
  public WizardPage(String icon, String title, String message) {
    this.icon = icon;
    this.pageTitle = title;
    this.message = message;
    initialize();
  }

  /**
   * invoked after the page is hidden
   */
  public void afterHide() {
    // override and implement
  }

  /**
   * invoked after page is displayed
   */
  public void afterShow() {
    // override and implement
  }

  /**
   * invoked before page is hidden
   */
  public void beforeHide() {
    // override and implement
  }

  /**
   * invoked before page is displayed
   */
  public void beforeShow() {
    // override and implement
  }

  /**
   * create page ui component
   * 
   * @return
   */
  protected abstract Widget createPageComponent();

  /**
   * 
   * getter for icon
   * 
   * @return the icon
   */
  public String getIcon() {
    return icon;
  }

  /**
   * 
   * getter for message
   * 
   * @return the message
   */
  public String getMessage() {
    return message;
  }

  /**
   * 
   * getter for pageTitle
   * 
   * @return the pageTitle
   */
  public String getPageTitle() {
    return pageTitle;
  }
  
  /**
   * getter for wizard
   * 
   * @return the wizard
   */
  public Wizard getWizard() {
    return wizard;
  }

  /**
   * 
   */
  private void initialize() {
    initWidget(createPageComponent());
  }

  /**
   * determine if the page is complete
   * 
   * @return true if page is complete, otherwise false
   */
  public boolean isComplete() {
    return true;
  }

  /**
   * handle populating data in UI components
   * 
   * this is called when the wizard displays the page
   * 
   */
  protected void populate() {
    // override and implement
  }

  /**
   * setter for icon
   * 
   * @param icon the icon to set
   */
  public void setIcon(String icon) {
    this.icon = icon;
  }

  /**
   * setter for message
   * 
   * @param message the message to set
   */
  public void setMessage(String message) {
    this.message = message;
  }

  /**
   * setter for pageTitle
   * 
   * @param pageTitle the pageTitle to set
   */
  public void setPageTitle(String pageTitle) {
    this.pageTitle = pageTitle;
  }

  /**
   * set wizard for page
   */
  protected void setWizard(Wizard wizard) {
    this.wizard = wizard;
  }

  /**
   * handle storing data from UI components
   * 
   * this will get called when the wizard is changing pages or finished has been
   * pressed. When changing pages store() will be invoked on the current page
   * before showing the next page.
   */
  protected void store() {
    // override and implement
  }

}
